package cn.ittaoli.movie.service;

import cn.ittaoli.movie.dao.MovieMapper;
import cn.ittaoli.movie.dao.MovieMapperCustomer;
import cn.ittaoli.movie.model.Movie;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lub_lenovo on 2017/11/3.
 */
@Service
public class MovieService {
    @Autowired
    private MovieMapper movieMapper;
    @Autowired
    private MovieMapperCustomer movieMapperCustomer;

    public Integer add(Movie movie) {

        movie.setDirector(movie.getDirector().replace('，',','));
        movie.setActor(movie.getActor().replace('，',','));
        movie.setTags(movie.getTags().replace('，',','));
        return movieMapper.insert(movie);
    }

    public List<Movie> getAll(){
        return movieMapperCustomer.getAll();
    }

    public PageInfo<Movie> getPagedData(Integer pageNum,Integer numPerPage) {
        PageHelper.startPage(pageNum,numPerPage);
        List<Movie> slides=movieMapperCustomer.getPagedData();
        PageInfo<Movie> pageInfo=new PageInfo<Movie>(slides);
        return pageInfo;
    }

    public Movie getOne(Integer id) {
        return movieMapper.selectByPrimaryKey(id);
    }
}
